<template>
  <div style="width: 100%;height: 100%;margin-right: -20px;overflow:hidden;">
        <iframe ref="iframe" @load="loaded" id="show-iframe" scrolling="no"
                style="  width: 100%; height: 100%; top: 0;left:0; border: 0px;overflow:scroll;overflow-x:auto;overflow-y:hidden"
                :src="src">

        </iframe>
<!--    <iframe ref="iframe" id="show-iframe" scrolling="no"-->
<!--            style="  width: 100%; height: 100%; top: 0;left:0; border: 0px;overflow:scroll;overflow-x:auto;overflow-y:hidden"-->
<!--            :src="src">-->

<!--    </iframe>-->
  </div>

</template>

<script>


  // xhr.open('GET', 'info.json');
  // xhr.send();

  export default {
    middleware: 'metaTitle',
    meta: {title: '文件管理'},
    name: "files",
    mounted() {
      //   // 在外部vue的window上添加postMessage的监听，并且绑定处理函数handleMessage
      //window.addEventListener('load', this.handleMessage)

      //this.iframeWin = this.$refs.iframe.contentWindow

      // this.iframeWin.addEventListener('click', this.handleMessage)
     // setTimeout(() => {
     //    //var iframe = document.querySelector("#show-iframe");
     //    var iframe = this.$refs.iframe;
     //    this.populateIframe(iframe, [["Authorization", "Bearer " + '44444444']]);
     //  }, 0);
    },
    created() {

    },
    data() {
      return {
        src: '/cb',
       //src: '',
        iframeWin: {}
      }
    },
    methods: {
      populateIframe(iframe, headers) {
        // var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest
        // var xhr = new XMLHttpRequest()
        var xhr = new XMLHttpRequest();
        var curPath = window.document.location.host;
        xhr.open("GET", 'https://' + curPath + '/fb');
       xhr.responseType = "blob";
        headers.forEach((header) => {
          xhr.setRequestHeader(header[0], header[1]);
        });
        xhr.onreadystatechange = () => {
          if (xhr.readyState === xhr.DONE) {
            if (xhr.status === 200) {
              //console.log(xhr.response)
              iframe.src = URL.createObjectURL(xhr.response);
            }
          }
        };
        xhr.send();
      },
      loaded() {
      },
      handleMessage(event) {
        // 根据上面制定的结构来解析iframe内部发回来的数据
        const data = event.data
        console.log(event)
        switch (data.cmd) {
          case 'returnFormJson':
            // 业务逻辑
            break
          case 'returnHeight':
            // 业务逻辑
            break
        }
      }
    },

  }
</script>

<style scoped>

</style>
